home *** CD-ROM | disk | FTP | other *** search
- /* Shared definitions for Eclectus integration utilities
- Copyright (C) 1988, 1989 Free Software Foundation, Inc.
-
- This file is part of the Eclectus integration utilities.
-
- Eclectus integration utilities are free software; you can redistribute
- it and/or modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 1, or
- (at your option) any later version.
-
- Eclectus integration utilities is distributed in the hope that it
- will be useful, but WITHOUT ANY WARRANTY; without even the implied
- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with the Eclectus integration utilities; see the file COPYING.
- If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
- MA 02139, USA. */
-
- #ifndef _DIFF
- #define _DIFF
-
- #ifndef DF_COMPILER_MSC /* MSC uses these modifiers to control argument passing */
- #define __fastcall /* pass arguments in registers */
- #define __cdecl /* C calling conventions; necessary for var args */
- #endif
-
- #ifdef DF_DEBUG
- #include "DebugMalloc.h"
- #endif
-
- #include <limits.h>
- #include <stdio.h>
-
- #define bcopy(s,d,n) (void) memcpy((d),(s),(n))
- #define bcmp(s1,s2,n) (void) memcmp((s1),(s2),(n))
- #define bzero(s,n) (void) memset((s),0,(n))
-
- #define TRUE 1
- #define FALSE 0
-
- #define DIFFERENCE_SCRIPT_START_STRING "# Created by Eclectus Difference integration utility\n"
- #define VERSION_STRING "1.10"
-
- #define COLLISION_PREFIX "!"
- #define LENGTH_OF_COLLISION_PREFIX 1
- #define HEX_LINE_LENGTH 0X30
-
- #ifdef DF_MACHINE_MACINTOSH
- #define DIRECTORY_CHAR ':'
- #define MAXPATHLEN 255
- #elif defined (DF_MACHINE_NEXT)
- #define DIRECTORY_CHAR '/'
- #elif defined (DF_MACHINE_WINDOWS)
- #define DIRECTORY_CHAR '\\'
- #else
- #error Define DIRECTORY_CHAR for your machine
- #endif
-
- /* Program error messages messages */
- enum {
- BAD_SCRIPT_FORMAT,
- BAD_SCRIPT_FOR_SOURCE,
- CANT_CREATE_DIRECTORY,
- CANT_CREATE_FILE,
- CANT_OPEN_FILE,
- HASH_DOESNT_MATCH,
- MEMORY_ERROR,
- MIXED_FILE_TYPES_DONT_MERGE,
- NOT_ASCII,
- PATH_TOO_LONG,
- THREE_OR_MORE_MERGE_FILES,
- THREE_UN_DIFFERENCE_FILES,
- TWO_FILES_ONLY,
- UNEXPECTED_IO_ERROR,
- UNEXPECTED_OPTION,
- MAX_ERROR_KIND = UNEXPECTED_OPTION};
-
- /* Types returned by file type */
- enum {
- BAD_FILE_TYPE,
- BINARY_TYPE,
- DIRECTORY_TYPE,
- TEXT_TYPE,
- MAX_FILE_TYPE_KIND = TEXT_TYPE};
-
- /* Attribute bits for CopyFileAttributes */
- #define LOCK_MASK 1
- #define DATE_MASK 2
- #define RESOURCE_MASK 4
-
- /* Rotate a value n bits to the left. */
- #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
- #define ROL(v, n) ((v) << (n) | (v) >> (UINT_BIT - (n)))
-
- /* Given a hash value and a new character, return a new hash value. */
- #define HASH(h, c) ((c) + ROL (h, 7))
-
- /* The result of comparison is an "edit script": a chain of `struct change'.
- Each `struct change' represents one place where some lines are deleted
- and some are inserted.
-
- LINE0 and LINE1 are the first affected lines in the two files (origin 0).
- DELETED is the number of lines deleted here from file 0.
- INSERTED is the number of lines inserted here in file 1.
-
- If DELETED is 0 then LINE0 is the number of the line before
- which the insertion was done; vice versa for INSERTED and LINE1. */
-
- struct change
- {
- struct change *link; /* Previous or next edit command */
- int inserted; /* # lines of file 1 changed here. */
- int deleted; /* # lines of file 0 changed here. */
- int line0; /* Line number of 1st deleted line. */
- int line1; /* Line number of 1st inserted line. */
- };
-
- /* Structures that describe the input files. */
-
- /* Data on one line of text. */
-
- struct line_def {
- char *text;
- int length;
- unsigned hash;
- /* The MPW 3.2 C compiler has a bug indexing arrays longer than 32K that have an element size of 12 */
- #ifdef DF_COMPILER_MPW
- int unused;
- #endif
- };
-
- /* Data on one input file being compared. */
-
- struct file_data {
- char *buffer; /* Buffer in which text of file is read. */
- unsigned int buffered_chars; /* Number of valid characters now in the buffer. */
- unsigned int buffered_lines; /* Number of elements of linbuf containing valid data. */
- unsigned int bufsize; /* Allocated size of buffer. */
- char *changed_flag; /* Vector, indexed by real origin-0 line number, containing 1 for
- * a line that is an insertion or a deletion. The results of
- * comparison are stored here. */
- FILE *desc; /* File descriptor */
- int dir_p; /* 1 if file is a directory */
- int equiv_max; /* 1 more than the maximum equivalence value used for this or its
- * sibling file. */
- int *equivs; /* free when done Vector, indexed by line number, containing an
- * equivalence code for each line. It is this vector that is actually
- * compared with that of another file to generate differences. */
- struct change *highLimitPtr; /* a temporary variable used by Merge */
- struct line_def *linbuf; /* Array of data on analyzed lines of this chunk of this file. */
- unsigned int linbufsize; /* Allocated size of linbuf array (# of elements). */
- struct change *lowLimitPtr; /* a temporary variable used by Merge */
- int missing_newline; /* 1 if file ends in a line with no final newline. */
- const char *namePtr; /* File name */
- struct file_data *nextFilePtr; /* Pointer to next file in a list of files */
- int nondiscarded_lines; /* Total number of nondiscarded lines. */
- char *prefix_end; /* Pointer to end of prefix of this file to ignore when hashing. */
- unsigned int prefix_lines; /* Count of lines in the prefix. */
- int *realindexes; /* Vector mapping virtual line numbers (not counting discarded lines)
- * to real ones (counting those lines). Both are origin-0. */
- struct change *scriptPtr; /* a pointer to a list of differences between this file and another */
- char *suffix_begin; /* Pointer to start of suffix of this file to ignore when hashing. */
- int suffix_lines; /* Count of lines in the suffix. */
- int *undiscarded; /* Vector, like the previous one except that the elements for
- * discarded lines have been squeezed out. */
- int version; /* version indicated order of file in Merge command string */
- };
-
- /*
- * fileNameListType is a variable length structure with numberOfItems in the names
- * array. Each item in the array consists of 0 or more characters followed by a null
- * character (i.e. a sequence of null terminated strings stored back to back). The
- * list is terminated with a extra null (i.e. a null string). Unfortunately ANSI C
- * requires a single element in this array making the syntax of variable length types
- * extremely awkward.
- */
-
- typedef struct fileNameListType {
- unsigned int numberOfItems;
- char names[1];
- } fileNameListType, *fileNameListPType;
-
- /* Declare globals */
-
- extern const char *ECMessagessArray [MAX_ERROR_KIND + 1];
-
- /* Declare functions. */
- extern void AppendCharToPathName (char *destinationCharPtr, const char theChar);
- extern void AppendStringToPathName (char *destinationCharPtr, const char *suffixCharPtr);
- extern void diff_2_files (register struct file_data *file0Ptr,
- register struct file_data *file1Ptr);
- extern void CopyFileAttributes (const char *sourceNamePtr,
- const char *destNamePtr,
- const int attributes);
- extern FILE *CreateTypedFile (const char *pathCharPtr, int binary);
- extern void Error (int errorKind);
- extern void ErrorWithStringArgument (int errorKind, const char *argumentStringPtr);
- extern int FileType (const char *pathCharPtr);
- extern void freeFile (register struct file_data *filePtr);
- extern int IgnoreFile (const char *nameSuffixPtr);
- extern int line_cmp (struct line_def *s1, struct line_def *s2);
- extern int MakeDirectory (const char *pathCharPtr);
- extern void print_rcs_script (struct file_data *file0Ptr, struct file_data *file1Ptr);
- extern fileNameListPType ReadDirectory (const char *pathCharPtr);
- extern void read_files (register struct file_data *file0Ptr, register struct file_data *file1Ptr);
- extern void slurp (struct file_data *filePtr);
- extern void *xmalloc (size_t size);
- extern void *xrealloc (void *old, size_t size);
- extern void RemoveNameSuffix (char *namePtr);
-
- #endif
-